﻿using System;
using System.Data;
using System.Data.OleDb;

namespace ControlExplorer.samples.MoveColumns
{
  public partial class Overview : SpreadDemoPage
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      if (IsPostBack) return;

      FpSpread1.Sheets[0].SheetName = "Moving";
      FpSpread1.Sheets[0].AllowColumnMove = true;
      FpSpread1.DataSource = GetTb_Customers();
      FpSpread1.DataBind();

      ApplyCustomerSeting(FpSpread1.Sheets[0]);
      this.FpSpread1.UseClipboard = false;
    }

    private DataSet GetTb_Customers()
    {
      string constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Northwind.mdb;Persist Security Info=True";
      string sqlstr;

      sqlstr = "SELECT top 20 * FROM Customers";
      DataSet Customers = new DataSet();
      using (OleDbConnection myconn = new OleDbConnection(constr))
      {
        OleDbDataAdapter sqlAdapter1 = new OleDbDataAdapter(sqlstr, myconn);
        sqlAdapter1.Fill(Customers, "Customers");
      }
      return Customers;
    }

    private void ApplyCustomerSeting(FarPoint.Web.Spread.SheetView sheet)
    {
      sheet.SetColumnLabel(0, 0, "ID");
      sheet.SetColumnLabel(0, 1, "公司名称");
      sheet.SetColumnLabel(0, 2, "姓名");
      sheet.SetColumnLabel(0, 3, "标题");
      sheet.SetColumnLabel(0, 4, "地址");
      sheet.SetColumnLabel(0, 5, "市");
      sheet.SetColumnLabel(0, 6, "区域");
      sheet.SetColumnLabel(0, 7, "邮政编码");
      sheet.SetColumnLabel(0, 8, "国家");
      sheet.SetColumnLabel(0, 9, "电话");
      sheet.SetColumnLabel(0, 10, "传真");

      sheet.SetColumnWidth(0, 60);
      sheet.SetColumnWidth(1, 210);
      sheet.SetColumnWidth(2, 150);
      sheet.SetColumnWidth(3, 90);
      sheet.SetColumnWidth(4, 185);
      sheet.SetColumnWidth(5, 100);
      sheet.SetColumnWidth(6, 55);
      sheet.SetColumnWidth(7, 75);
      sheet.SetColumnWidth(8, 75);
      sheet.SetColumnWidth(9, 110);
      sheet.SetColumnWidth(10, 110);
    }
  }
}